package com.qiannianai.app.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.yoomiito.app.Constant;
import com.yoomiito.app.base.App;
import com.yoomiito.app.utils.AllCode;
import com.yoomiito.app.utils.EventMessage;

import org.greenrobot.eventbus.EventBus;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.msgApi.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        App.msgApi.handleIntent(getIntent(), this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            EventMessage message = new EventMessage();
            message.setEventType(Constant.PAY_RESULT);
            switch (resp.errCode) {
                case 0:
                    message.setCode(AllCode.Success);
                    break;
                case -1:
                case -2:
                    message.setCode(AllCode.Fail);
                    break;
            }
            EventBus.getDefault().post(message);
        }
        WXPayEntryActivity.this.finish();
    }
}